<?php
/**
 * Data Model
 *
 * @property Data $ParentData
 * @property Data $ChildData
 */
class WxNativePay extends WechatAppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = false;

	public function getNative($param = array()){
	    App::import('Vendor','Wechat.WxPayApi',array('file'=>'wxpay'.DS.'WxPay.Api.php'));
	    $input = new WxPayUnifiedOrder();
	    $input->SetBody($param['body']);
	    $input->SetAttach($param['attach']);
	    $input->SetOut_trade_no($param['out_trade_no']);
	    $input->SetTotal_fee($param['fee']*100);
	    $input->SetTime_start(date("YmdHis"));
	    $input->SetTime_expire(date("YmdHis", time() + 6000));
	    $input->SetGoods_tag($param['tag']);
	    $input->SetNotify_url($param['notify']);
	    $input->SetTrade_type("NATIVE");
	    $input->SetProduct_id($param["product_id"]);
	    $order = WxPayApi::unifiedOrder($input);
	    if((isset($order['return_code']) && $order['return_code'] == 'FAIL') 
	        ||(isset($order['result_code']) && $order['result_code'] == 'FAIL')){
	        return array(
	            'return_code'=>'FAIL',
	            'return_msg'=>isset($order['err_code_des'])?$order['err_code_des']:$order['return_msg']
	        );
	    }
	    return $order;
	}
	
	 
}
